<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$object_type = UV::readMQ(strip_tags($route->GET("type")));
$object_id = UV::readInt(strip_tags($route->GET("id")));

if ($object_type == "company"){
	$company = $db->getRow("select `C`.`name`,`C`.`address`,`C`.`phone`,`city`.`name` as `city_name` from `companies` as `C`,`city` where `C`.`company_id` = '$object_id' and `C`.`city_id` = `city`.`city_id` limit 1");
	if ($company)
		echo $answer = '{"name":"'.$company['name'].'","address":"'.$company['address'].'","phone":"'.$company['phone'].'","city":"'.$company['city_name'].'"}';
} elseif ($object_type == "office"){
	$company = $db->getRow("select `C`.`name`,`O`.`address`,`O`.`phone`,`city`.`name` as `city_name` from `companies` as `C`,`additional_office` as `O`,`city` where `C`.`company_id` = `O`.`company_id` and `O`.`ao_id` = '$object_id' and `C`.`city_id` = `city`.`city_id` limit 1");
	if ($company)
		echo $answer = '{"name":"'.$company['name'].'","address":"'.$company['address'].'","phone":"'.$company['phone'].'","city":"'.$company['city_name'].'"}';
} elseif ($object_type == "broker") {
	$broker = $db->getRow("select `B`.`name`,`B`.`address`,`B`.`phone`,`city`.`name` as `city_name` from `brokers` as `B`,`city` where `B`.`broker_id` = '$object_id' and `B`.`city_id` = `city`.`city_id` limit 1");
	if ($broker)
		echo $answer = '{"name":"'.$broker['name'].'","address":"'.$broker['address'].'","phone":"'.$broker['phone'].'","city":"'.$broker['city_name'].'"}';
}

?>